﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Dapper;

namespace YmtAuth.Domain.Repository.MySql
{
    public interface IMySQLRepository<TEntity>
    {
        TEntity First(dynamic where);
        long Insert(TEntity entity);
        long Insert(TEntity entity, bool ignoreDuplicate);
        void InsertAsync(TEntity entity, bool ignoreDuplicate); 
        int Update(IDictionary<string, object> updateColumns, IDictionary<string, object> where);
        int Execute(string sql, IDictionary<string, object> parameter);
        int Execute(string sql, SqlParameter[] parameter, int? timeOut = null, CommandType? commandType = null);
        IEnumerable<TEntity> Query(string sql, DynamicParameters parameters, int? timeOut = null,CommandType? commandType = null,bool buffered = true);
        IEnumerable<TEntity> Query<T1, T2, TEntity>(string sql, DynamicParameters parameters, Func<T1, T2, TEntity> convert,
                                                    string splitOn, int? timeOut = null, CommandType? commandType = null,
                                                    bool buffered = true);
        TEntity QueryMultiple(string sql, SqlParameter[] parameters, Func<SqlMapper.GridReader, TEntity> convert,
                            int? timeOut = null, CommandType? commandType = null,
                            bool buffered = true);
        int SaveChange(TEntity entity);
        void SaveChange(IEnumerable<TEntity> entities);
        int TrySaveChange(TEntity entity, Action<Exception> errorHandle=null);
    }
}
